<script setup>
    import {inject,ref} from 'vue'
    import useWebSiteStore from '@/store/websiteStore'
    const webSiteStore = useWebSiteStore()

    const {isShow,setIsShow} = inject('dialog-visible')
    const {dialogUrl} = inject('dialog-url')


    const isSubmit = ref(false)

    const handleAddClick = async () =>{
        isSubmit.value = true
        const result = await myApi.sendUrl(dialogUrl.value)
        if(result.msg){
            myApi.alert(result.msg)
            isSubmit.value = false
            return
        }
        webSiteStore.add(result)
        isSubmit.value = false
        setIsShow(false)
    }
</script>

<template>
    <div class="dialog-wrap" v-if="isShow">
        <div class="content">
            <div class="input">
                <input type="text" @keyup.enter='handleAddClick' v-model="dialogUrl" placeholder="请输入网址" :disabled="isSubmit">
            </div>
            <div class="btns">
                <button @click="handleAddClick" :disabled="isSubmit">添加</button>
                <button @click="setIsShow(false)" :disabled="isSubmit">取消</button>
            </div>      
        </div>
    </div>
</template>

<style lang="css">
    .dialog-wrap{
        position: absolute;
        top: 0px;
        left: 0px;
        right: 0px;
        bottom: 0px;
        background-color: rgba(0, 0, 0, 0.8);
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .content{
        width: 100px;
        padding: 0 20px;
    }
    .content input{
        height: 30px;
        width: 100px;
        outline: none;
        margin-bottom: 10px;
        font-size: 12px;
    }
    .btns button{
        height: 30px;
        margin-right: 10px;
        font-size: 12px;
        padding: 0 20px;
    }
</style>